unit CapturaDocumentos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, Buttons;

type
  TFormCapturaDocumentos = class(TForm)
    GroupBox1: TGroupBox;
    RB_LeituraX: TRadioButton;
    RB_LMF: TRadioButton;
    RB_FitaDetalhe: TRadioButton;
    RB_Parametros: TRadioButton;
    GroupBox2: TGroupBox;
    RB_CRZ: TRadioButton;
    RB_Data: TRadioButton;
    GroupBox3: TGroupBox;
    RB_Simples: TRadioButton;
    RB_Completa: TRadioButton;
    GroupBox4: TGroupBox;
    RB_COO: TRadioButton;
    RB_FD_Data: TRadioButton;
    Label1: TLabel;
    Label2: TLabel;
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    MaskEdit3: TMaskEdit;
    MaskEdit4: TMaskEdit;
    Label3: TLabel;
    Label4: TLabel;
    BitBtn1: TBitBtn;
    CheckBox1: TCheckBox;
    procedure RB_LMFClick(Sender: TObject);
    procedure RB_FitaDetalheClick(Sender: TObject);
    procedure RB_ParametrosClick(Sender: TObject);
    procedure RB_LeituraXClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure RB_DataClick(Sender: TObject);
    procedure RB_FD_DataClick(Sender: TObject);
    procedure RB_COOClick(Sender: TObject);
    procedure RB_CRZClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormCapturaDocumentos: TFormCapturaDocumentos;
  tipo, faixai, faixaf:string;

implementation

uses principal, Retorno, funcoesapoio, declaracoes;

{$R *.dfm}

procedure TFormCapturaDocumentos.RB_LMFClick(Sender: TObject);
begin
        GroupBox2.Enabled:=true;
        GroupBox3.Enabled:=true;
        GroupBox4.Enabled:=false;
        MaskEdit3.Text:=#0;
        MaskEdit4.Text:=#0;
end;

procedure TFormCapturaDocumentos.RB_FitaDetalheClick(Sender: TObject);
begin
        GroupBox2.Enabled:=false;
        GroupBox3.Enabled:=false;
        GroupBox4.Enabled:=true;
        MaskEdit1.Text:=#0;
        MaskEdit2.Text:=#0;

end;

procedure TFormCapturaDocumentos.RB_ParametrosClick(Sender: TObject);
begin
        GroupBox2.Enabled:=false;
        GroupBox3.Enabled:=false;
        GroupBox4.Enabled:=false;

end;

procedure TFormCapturaDocumentos.RB_LeituraXClick(Sender: TObject);
begin
        GroupBox2.Enabled:=false;
        GroupBox3.Enabled:=false;
        GroupBox4.Enabled:=false;
        MaskEdit1.Text:=#0; MaskEdit2.Text:=#0; MaskEdit3.Text:=#0;MaskEdit4.Text:=#0;
end;

procedure TFormCapturaDocumentos.FormShow(Sender: TObject);
begin
        GroupBox2.Enabled:=false;
        GroupBox3.Enabled:=false;
        GroupBox4.Enabled:=false;
end;

procedure TFormCapturaDocumentos.BitBtn1Click(Sender: TObject);
begin
        faixai:=#0; faixaf:=#0; tipo:=#0;
        if RB_leituraX.Checked then  tipo := '0'
        else if RB_LMF.Checked and RB_CRZ.Checked and RB_Simples.Checked Then begin
                tipo := '1';faixai:=Maskedit1.Text ;faixaf:=Maskedit2.Text ;
        end

        else if RB_LMF.Checked and RB_CRZ.Checked and RB_Completa.Checked Then begin
                tipo := '2';faixai:=Maskedit1.Text ;faixaf:=Maskedit2.Text ;
        end
        else if RB_LMF.Checked and RB_Data.Checked and RB_Simples.Checked Then begin
                tipo := '3';faixai:=Maskedit1.Text ;faixaf:=Maskedit2.Text ;
        end
        else if RB_LMF.Checked and RB_Data.Checked and RB_Completa.Checked Then begin
                tipo := '4';faixai:=Maskedit1.Text ;faixaf:=Maskedit2.Text ;
        end
        else if RB_FitaDetalhe.Checked and RB_COO.Checked Then begin
                tipo := '5';faixai:=Maskedit3.Text ;faixaf:=Maskedit4.Text ;
        end
        else if RB_FitaDetalhe.Checked and RB_FD_Data.Checked Then begin
                tipo := '6';faixai:=Maskedit3.Text ;faixaf:=Maskedit4.Text ;
        end
        else if RB_Parametros.Checked then begin
                tipo := '7'; faixai:=Maskedit3.Text ;faixaf:=Maskedit4.Text ;
        end;

        FormPrincipal.Statusbar1.Panels[0].Text:='Captura Documentos'; WaitProcess;
        Resposta:= ECF_CapturaDocumentos(tipo, faixai, faixaf, 'C:\SWEDA\SAIDA.TXT', inttostr(ord(checkbox1.checked)));

        FormPrincipal.Memo1.Lines.Add('Captura Documentos:'+inttostr(Resposta));
        FormPrincipal.Memo1.Lines.Add('');

        if Resposta = 1 then
        if MessageDlg('Deseja abrir o arquivo C:\SWEDA\SAIDA.TXT ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
                FormPrincipal.OpenDialog1.FileName:='C:\SWEDA\SAIDA.TXT';
                FormPrincipal.OpenDialog1.Execute;
                FormRetorno.Caption:=FormPrincipal.OpenDialog1.FileName;
                FormRetorno.RichEdit1.Lines.LoadFromFile(FormPrincipal.OpenDialog1.FileName);
                FormRetorno.Show;
        end;

        VerificaRetornoFuncao(Resposta);
        Refresh;

end;

procedure TFormCapturaDocumentos.RB_DataClick(Sender: TObject);
begin
        MaskEdit1.EditMask:='!99/99/00;1;_';
        MaskEdit2.EditMask:='!99/99/00;1;_';
        MaskEdit1.Text:=FormatDateTime('dd/mm/yy',date);
        MaskEdit2.Text:=FormatDateTime('dd/mm/yy',date);

end;

procedure TFormCapturaDocumentos.RB_FD_DataClick(Sender: TObject);
begin
        MaskEdit3.EditMask:='!99/99/00;1;_';
        MaskEdit4.EditMask:='!99/99/00;1;_';
        MaskEdit3.Text:=FormatDateTime('dd/mm/yy',date);
        MaskEdit4.Text:=FormatDateTime('dd/mm/yy',date);

end;

procedure TFormCapturaDocumentos.RB_COOClick(Sender: TObject);
begin
        MaskEdit3.EditMask:='!000000;1;_';
        MaskEdit4.EditMask:='!000000;1;_';
        MaskEdit3.Text:='000001';
        MaskEdit4.Text:='999999';

end;

procedure TFormCapturaDocumentos.RB_CRZClick(Sender: TObject);
begin
        MaskEdit1.EditMask:='!0000;1;_';
        MaskEdit2.EditMask:='!0000;1;_';
        MaskEdit1.Text:='0001';
        MaskEdit2.Text:='9999';

end;

end.
